package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/menu")
public class MenuControllor {

    @Reference
    private MenuService menuService;

    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Menu> menus= menuService.findAll();
            return new Result(true,"查询菜单成功",menus);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询菜单失败");
        }
    }

    @RequestMapping("/findMenuIdsByRoleId")
    public Result findMenuIdsByMenuId(Integer roleId){
        try {
            List<Integer> menuIds=  menuService.findMenuIdsByRoleId(roleId);
            return new Result(true,"查询菜单信息成功",menuIds);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询菜单信息失败");
        }
    }
}
